#include "framemaker.h"

FrameMaker::FrameMaker(void):sequence(0)
{
	recvbuf.clear();
	sendbuf.clear();
}
void FrameMaker::makeLogin(void)
{
	Frame& f = sendbuf.frame;

	sendbuf.clear();
	f.header.initDataMinLen();
	f.control.initActiveS2M();
	f.address = address;
	f.function.initLogin();
	f.sequence.initSingleAck(sequence);
	f.append(sendbuf);

	DataType(1, 0).append(sendbuf);

	sendbuf.make();
}
void FrameMaker::makeConfirm(void)
{
	Frame& f = sendbuf.frame;

	f.header.initDataMinLen();
	f.control.initActiveS2M();
	f.address = address;
	f.function.initConfirm();
	f.sequence.initSingleNack(sequence);
}
void FrameMaker::makeHeartbeat(void)
{
	Frame& f = sendbuf.frame;

	sendbuf.clear();
	f.header.initDataMinLen();
	f.control.initActiveS2M();
	f.address = address;
	f.function.initHeartbeat();
	f.sequence.initSingleAck(++sequence);
	f.sequence.TPV = 1;
	f.append(sendbuf);

	DataType(3,0).append(sendbuf);
	AUXTime(sequence).append(sendbuf);

	sendbuf.make();
}
void FrameMaker::makeResponse(void)
{
	sendbuf.clear();
	recvbuf.frame.append(sendbuf);
	Frame& f = sendbuf.frame;
	f.header.initDataMinLen();
	f.control.DIR  = !(f.control.DIR);
	f.control.PRM  = !(f.control.PRM);
	f.control.FUN  = CONTROL_FUN_PASIVE_08_DATA;
	f.sequence.CON = SEQUENCE_CON_NO;
	f.sequence.TPV = SEQUENCE_TPV_YES;
}
void FrameMaker::addAUXTime(void)
{
	sendbuf.frame.sequence.TPV = 1;
	AUXTime(sequence).append(sendbuf);
	sendbuf.make();
}
